package org.thunms.schedule.quartz.service;

import java.io.Serializable;
import java.text.ParseException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thunms.framework.utils.UtilDateTime;

public class CronExpressionTest implements Serializable {
	private static final long serialVersionUID = -1749035772029804331L;
	private static final Logger logger=LoggerFactory.getLogger(CronExpressionTest.class);
	
	public static String testCronExpression (String cron) {
		StringBuffer br=new StringBuffer("<div style=\"width:100%; height:400px; overflow:auto;\">");
		try {
			CronExpressionEx exp = new CronExpressionEx(cron);
			 java.util.Date dd = new java.util.Date();
			for (int i = 1; i <= 100; i++) {
		          dd = exp.getNextValidTimeAfter(dd);
		          br.append(i + ": " + UtilDateTime.toDateString(dd, "yyyy-MM-dd HH:mm:ss") + "<br/>");
		          dd = new java.util.Date(dd.getTime() + 1000);
		        }
		} catch (ParseException e) {
			logger.error("无效的表达式:"+cron,e);
			br.append("无效的表达式:"+cron);
		}
		return br.append("</div>").toString();
		
	}
}
